package com.wwwarehouse.usercenter.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.custom_widget.CircleImageView;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.business_relationship.GetRelationSalesmansBean;

import java.util.ArrayList;

/**
 * 订单导入设置主页Adapter
 * Created by ShineF on 2017/8/11 0011.
 */

public class BRCFCDSelectSalesmanAdapter extends RecyclerView.Adapter<BRCFCDSelectSalesmanAdapter.ImportOrdersPagersHolder> {

    private Context mContext = null;
    private ArrayList<GetRelationSalesmansBean> mList = null;
    private int mHeight = 0;

    public BRCFCDSelectSalesmanAdapter(Context context, ArrayList<GetRelationSalesmansBean> list, int height) {
        this.mContext = context;
        this.mList = list;
        this.mHeight = height;
    }

    @Override
    public ImportOrdersPagersHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ImportOrdersPagersHolder(
                View.inflate(mContext, R.layout.adapter_select_distribution_recycle, null));
    }

    @Override
    public void onBindViewHolder(ImportOrdersPagersHolder holder, final int position) {
		final GetRelationSalesmansBean listBean = mList.get(position);
		RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.mRlItem.getLayoutParams();
        params.height = (mHeight - ConvertUtils.dip2px(mContext, 20)) / 3;
        holder.mRlItemSelect.setVisibility(View.GONE);
        if (listBean.getIsMySalesman().equals("1")) {
            holder.mRlItem.setVisibility(View.VISIBLE);
        } else{
            holder.mRlItem.setVisibility(View.GONE);
        }
        if (null != listBean.getUserFaceUrl()) {
            BaseApplication.getApplicationInstance().displayImg(listBean.getUserFaceUrl(), holder.mIvHeadPic);
        } else {
            holder.mIvHeadPic.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.select_permission_pic));
        }
        if (null != listBean.getUserName()) {
            holder.mTvName.setText(listBean.getUserName());
        }
        if (null != listBean.getUserContact()) {
            holder.mTvPhoneNumber.setText(listBean.getUserContact());
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public interface OnItemClickListener {
        void ItemClickListener(int position, View view, GetRelationSalesmansBean data);
    }

    class ImportOrdersPagersHolder extends RecyclerView.ViewHolder {

        RelativeLayout mRlItem;
        RelativeLayout mRlItemSelect;
        CircleImageView mIvHeadPic;
        TextView mTvName;
        TextView mTvPhoneNumber;

        ImportOrdersPagersHolder(View itemView) {
            super(itemView);
            mRlItem = (RelativeLayout) itemView.findViewById(R.id.rl_item);
            mRlItemSelect = (RelativeLayout) itemView.findViewById(R.id.rl_item_select);
            mIvHeadPic = (CircleImageView) itemView.findViewById(R.id.iv_permission_user_pic);
            mTvName = (TextView) itemView.findViewById(R.id.tv_permission_user_name);
            mTvPhoneNumber = (TextView) itemView.findViewById(R.id.tv_permission_user_number);
        }
    }
}
